public with sharing class ContactTriggerHandler {
public void OnAfterContactPimsId(List<Contact> contactlist){
    
    Set<String> partnerid=new Set<String>();
    map<String,Id> contactmap=new map<String,Id> ();
    if(contactlist!=null&&contactlist.size()>0){
        for(Contact con: contactlist){
            partnerid.add(con.Partner_Contact_ID__c);
            contactmap.put(con.Partner_Contact_ID__c,con.Id);
       
        }
        List<PIMS_Reserved_Id__c> pimsid=[select Id,contact__c,PIMS_Id__c,Used__c from PIMS_Reserved_Id__c where PIMS_Id__c IN: partnerid];
        List<PIMS_Reserved_Id__c> updatelist=new List<PIMS_Reserved_Id__c>();
        
        if(pimsid!=null){
            for(PIMS_Reserved_Id__c pims : pimsid){
                 pims.contact__c=contactmap.get(pims.PIMS_Id__c);
                 pims.Used__c=true;
                 updatelist.add(pims);
            }
        }
             
     if(!updatelist.isEmpty()){
         try{ 
          update updatelist;
          }catch(Exception e1){system.debug('## Exception while updating : '+e1);}
       }
    }
}
public void OnbeforeContactPimsId(List<Contact> contact){
    List<String> pimsid=new List<String>();
    List<PIMS_Reserved_Id__c> pimsidList=[select Id,PIMS_Id__c from PIMS_Reserved_Id__c where Used__c=false];
    for(PIMS_Reserved_Id__c pims:pimsidList)
    {
        pimsid.add(pims.PIMS_Id__c);
    }
    Integer i=0;
 if(contact !=null && contact.size()>0){    
    for(Contact con:contact){
        if(con.Partner_Contact_ID__c==null && pimsid[i]!=null){
            con.Partner_Contact_ID__c =pimsid[i];
            i++;
        }
    }
 }
}
public void OnbeforeContactNameId(List<Contact> contact){
 if(contact !=null && contact.size()>0){ 
    for(Contact con:contact){
        if(con.Name_Id__c==null){
               con.Name_Id__c= '1';
              }
    }
 }
}

}